package com.soulkun.smarthome.ui.main.scene.adapter

import android.content.Context
import android.view.View
import androidx.databinding.ObservableArrayList
import androidx.databinding.ViewDataBinding
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppRecycleItemMainSceneOnekeyListBinding
import com.soulkun.smarthome.logic.model.OnekeyData
import soulkun.library.mvvm.adapter.BaseDataBindingRecyclerViewAdapter
import soulkun.library.utils.toast

class AppMainSceneOnekeyListAdapter(context: Context, dataList: ObservableArrayList<OnekeyData>) :
    BaseDataBindingRecyclerViewAdapter<OnekeyData>(context, dataList) {

    override fun getContentLayoutResId(): Int {
        return R.layout.app_recycle_item_main_scene_onekey_list
    }

    override fun setContentViewHolderCreateListener(binding: ViewDataBinding) {
        (binding as AppRecycleItemMainSceneOnekeyListBinding).onClickListener = View.OnClickListener {
            when(it.id){
                R.id.iv_main_scene_onekey_list_icon_menu ->{
                    "点击单项菜单".toast()
                }
                else -> {
                    "点击执行".toast()
                }
            }
        }
    }

    override fun setContentViewHolderBindListener(binding: ViewDataBinding, dataPosition: Int) {
        val data = dataList[dataPosition]
        var sceneName = ""
        data.job.forEach {
            sceneName += "${it.jobName} "
        }
        (binding as AppRecycleItemMainSceneOnekeyListBinding).tvMainSceneOnekeyListTextOnekeyName.text =
            sceneName.trim()
        binding.tvMainSceneOnekeyListTextOnekeyJob.text = "${data.job.size}个任务"
    }

}